package com.example.toolbar.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.example.toolbar.R;

public class AllAcitonFragment extends Fragment {
	private ListView listView;
	private JSONArray jsonArray;
	private MAdapter mAdapter;
	private Context context;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		context = getActivity();
		View v = inflater.inflate(R.layout.city_wide_listview, null);
		listView = (ListView) v.findViewById(android.R.id.list);
		String s = "{   \"data\": [     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-19 17:08:45\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 17,       \"images\": \"\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": null,         \"avatar\": \"\",         \"dateline\": \"2015-08-14 11:28:21\",         \"email\": \"\",         \"gender\": \"UNKONW\",         \"id\": 38,         \"lastUpdate\": \"2015-08-14 11:28:21\",         \"latitude\": \"\",         \"longitude\": \"\",         \"nickName\": \"\",         \"userName\": \"ʷ����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-19 11:38:49\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 16,       \"images\": \"assets/images/fact/2015/08/e0881f2696a84df026d656689fc4e44b.png,assets/images/fact/2015/08/52311200fd123fbaccca6a0e4fc7ec41.png\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": null,         \"avatar\": \"\",         \"dateline\": \"2015-08-14 11:28:21\",         \"email\": \"\",         \"gender\": \"UNKONW\",         \"id\": 38,         \"lastUpdate\": \"2015-08-14 11:28:21\",         \"latitude\": \"\",         \"longitude\": \"\",         \"nickName\": \"\",         \"userName\": \"ʷ����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-19 11:30:39\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 15,       \"images\": \"assets/images/fact/2015/08/7c78eef4b20db0475910409b5877603b.png,assets/images/fact/2015/08/ce476b479250858b33fa0c4121926665.png\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": null,         \"avatar\": \"\",         \"dateline\": \"2015-08-14 11:28:21\",         \"email\": \"\",         \"gender\": \"UNKONW\",         \"id\": 38,         \"lastUpdate\": \"2015-08-14 11:28:21\",         \"latitude\": \"\",         \"longitude\": \"\",         \"nickName\": \"\",         \"userName\": \"ʷ����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-19 11:30:16\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 14,       \"images\": \"assets/images/fact/2015/08/b866c13b2c7f7d56d97ec555c21fa6f3.png\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": null,         \"avatar\": \"\",         \"dateline\": \"2015-08-14 11:28:21\",         \"email\": \"\",         \"gender\": \"UNKONW\",         \"id\": 38,         \"lastUpdate\": \"2015-08-14 11:28:21\",         \"latitude\": \"\",         \"longitude\": \"\",         \"nickName\": \"\",         \"userName\": \"ʷ����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-19 11:26:46\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 13,       \"images\": \"assets/images/fact/2015/08/3fca275a22e626d857a4a5d6e70c98aa.png\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": null,         \"avatar\": \"\",         \"dateline\": \"2015-08-14 11:28:21\",         \"email\": \"\",         \"gender\": \"UNKONW\",         \"id\": 38,         \"lastUpdate\": \"2015-08-14 11:28:21\",         \"latitude\": \"\",         \"longitude\": \"\",         \"nickName\": \"\",         \"userName\": \"ʷ����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-17 10:05:55\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 12,       \"images\": \"\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": \"LL\",         \"avatar\": \"\",         \"dateline\": \"2015-08-17 09:10:10\",         \"email\": \"\",         \"gender\": \"BOY\",         \"id\": 65,         \"lastUpdate\": \"2015-08-17 09:57:38\",         \"latitude\": \"22.1\",         \"longitude\": \"11.1\",         \"nickName\": \"�ļ�\",         \"userName\": \"����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-14 14:15:10\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 11,       \"images\": \"\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": \"HT\",         \"avatar\": \"\",         \"dateline\": \"2015-08-14 11:04:38\",         \"email\": \"1286734236@qq.com\",         \"gender\": \"BOY\",         \"id\": 37,         \"lastUpdate\": \"2015-08-14 11:04:38\",         \"latitude\": \"22.5\",         \"longitude\": \"23.1\",         \"nickName\": \"����\",         \"userName\": \"�׻���\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-14 14:13:26\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 10,       \"images\": \"\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": \"LL\",         \"avatar\": \"assets/images/avatar/1_avatar.png\",         \"dateline\": \"2015-08-06 17:23:06\",         \"email\": \"\",         \"gender\": \"BOY\",         \"id\": 1,         \"lastUpdate\": \"2015-08-19 13:16:52\",         \"latitude\": \"22.1\",         \"longitude\": \"11.1\",         \"nickName\": \"�ļ�\",         \"userName\": \"����\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-14 11:32:59\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 9,       \"images\": \"\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": null,         \"avatar\": \"\",         \"dateline\": \"2015-08-14 10:10:42\",         \"email\": \"hunangongdahou@163.com\",         \"gender\": null,         \"id\": 16,         \"lastUpdate\": \"2015-08-17 14:42:59\",         \"latitude\": \"22.1\",         \"longitude\": \"11.1\",         \"nickName\": \"hou\",         \"userName\": \"hou\"       }     },     {       \"address\": \"������\",       \"area\": \"YX\",       \"dateline\": \"2015-08-14 09:38:04\",       \"description\": \"�ɺ���ź\",       \"endLine\": \"2015-08-20 00:00:00\",       \"id\": 8,       \"images\": \"\",       \"peoples\": 20,       \"startLine\": \"2015-08-15 00:00:00\",       \"title\": \"�ͺɴ��\",       \"user\": {         \"area\": \"TY\",         \"avatar\": \"assets/images/avatar/4_avatar.png\",         \"dateline\": \"2015-08-14 09:31:03\",         \"email\": \"363798478@qq.com\",         \"gender\": \"GIRL\",         \"id\": 4,         \"lastUpdate\": \"2015-08-14 10:15:18\",         \"latitude\": \"22.1\",         \"longitude\": \"11.1\",         \"nickName\": \"�ļ�\",         \"userName\": \"л����\"       }     }   ],   \"message\": \"\",   \"success\": true }";
		jsonArray = JSON.parseObject(s).getJSONArray("data");
		mAdapter = new MAdapter();
		listView.setAdapter(mAdapter);
		Log.d("dxx", "sds");
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = new Intent("action_details");
				Log.d("dxx", "sds");
				startActivity(intent);
				
			}
		});
		return v;
	}

	class MAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return jsonArray.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// // final ViewHolder viewHolder;
			// if(convertView==null){
			// // convertView =
			// LayoutInflater.from(context).inflate(R.layout.all_action_item,
			// null);
			// viewHolder = new ViewHolder(convertView);
			// convertView.setTag(viewHolder);
			// }else{
			// viewHolder = (ViewHolder) convertView.getTag();
			// }
			// JSONObject obj = (JSONObject) jsonArray.get(position);
			// viewHolder.title.setText(obj.getString("title"));
			// viewHolder.content.setText(obj.getString("title"));
			// viewHolder.address.setText(obj.getString("address"));
			// viewHolder.peoples.setText(obj.getString("people"));
			// viewHolder.time.setText(obj.getString("startLine")+"~"+obj.getString("endLine"));
			convertView = LayoutInflater.from(context).inflate(
					R.layout.all_action_item, null);
			return convertView;
		}

	}

	// class ViewHolder{
	// public ViewHolder(View view) {
	// ViewUtils.inject(this, view);
	// }
	// @ViewInject(R.id.city_touxiang)
	// ImageView touxiang;
	// @ViewInject(R.id.city_aiimg)
	// ImageView actionImage;
	// @ViewInject(R.id.city_action_title)
	// TextView title;
	// @ViewInject(R.id.city_action_content)
	// TextView content;
	// @ViewInject(R.id.city_action_address)
	// TextView address;
	// @ViewInject(R.id.city_action_peoples)
	// TextView peoples;
	// @ViewInject(R.id.city_action_time)
	// TextView time;
	// @ViewInject(R.id.city_action_sign)
	// TextView sign;
	//
	// }

}
